<template>
  <div class="clearfix table-out search">
    <el-button
      type="primary"
      plain
      size="small"
      class="return pointer"
      @click="returnGo"
      ><i class="iconfont icon-fanhui"></i> 返回
    </el-button>
    <div class="clearfix top-return search-pub">
      <el-form :model="formData" label-width="auto">
        <el-select
          @change="getData"
          class="fxl margin10R"
          style="width: 120px"
          :placeholder="`请选择评审状态`"
          v-model="formData.pingszt"
        >
          <el-option
            v-for="item in pingsztlb"
            :key="item.itemValue"
            :label="item.itemText"
            :value="item.itemValue"
          >
          </el-option>
        </el-select>

        <!-- 动态搜素条件 -->
        <el-form-item class="fxl" v-for="(item, idx) in soustjList" :key="idx">
          <el-input
            style="width: 240px"
            clearable
            @change="getData"
            class="fxl margin10R pub-inp-wid"
            :placeholder="`请选择${item.biaot}`"
            v-model="formData[item.zidmc]"
            v-if="item.biaodkjlx == '1'"
          />
          <el-select
            @change="getData"
            class="fxl margin10R"
            style="width: 200px"
            :placeholder="`请选择${item.biaot}`"
            v-if="item.biaodkjlx == '2'"
            v-model="formData[item.zidmc]"
          >
            <el-option
              v-for="item2 in item.kongjsj.split(';')"
              :label="item2.split(',')[0]"
              :value="item2.split(',')[1]"
            >
            </el-option>
          </el-select>
          <el-cascader
            class="fxl margin10R"
            clearable
            style="width: 230px"
            v-if="item.biaodkjlx == '3'"
            @change="cascaderChangeData($event, item.zidmc)"
            :show-all-levels="true"
            :placeholder="`请选择${item.biaot}`"
            :props="props"
            v-model="formData[item.zidmc]"
            :options="cascaderData[item.zidmc]"
          ></el-cascader>
        </el-form-item>
        <el-button class="fxl" type="primary" @click="getData(1)"
        >查询
        </el-button
        >
        <el-button class="fxl" type="primary" @click="reset">重置</el-button>
      </el-form>
    </div>
    <el-table
      v-loading="tableLoading"
      :data="tableData"
      empty-text=" "
      class="tablePub top-return"
      :row-class-name="tableRowClassName"
    >
      <!--      <el-table-column prop="no" label="序号" width="80" align="center">-->
      <!--        <template #default="scope">-->
      <!--          <p>{{ scope.$index + 1 }}</p>-->
      <!--        </template>-->
      <!--      </el-table-column>-->
      <el-table-column label="序号" type="index" :index="getIndex" width="70" />
      <el-table-column
        prop="saisjcid_dictText"
        label="赛事进程"
        align="center"
        width="140"
      >
      </el-table-column>

      <!-- <el-table-column prop="zilshzt" label="资料审核状态" align="center">
      </el-table-column> -->

      <el-table-column prop="saisqyId_dictText" label="赛区" align="center">
      </el-table-column>

      <el-table-column
        :prop="item.zidmc"
        :label="item.biaot"
        v-for="(item, idx) in tableHeader"
        :key="idx"
        :width="item.width"
        :min-width="250"
        align="center"
      >
      </el-table-column>

      <el-table-column
        fixed="right"
        prop="oper"
        label="操作"
        width="180"
        align="center"
      >
        <template #default="scope">
          <el-button
          v-if="scope.row.pingszt == '待评审'"
            type="primary"
            size="small"
            @click="oper(scope.$index, scope.row)"
            >打分
          </el-button>
          <el-button
            v-if="scope.row.pingszt == '已评审'"
            type="primary"
            size="small"
            @click="oper(scope.$index, scope.row)"
            >重新打分
          </el-button>
          <el-popconfirm
            v-if="scope.row.pingszt == '已评审'"
            title="确认删除么?"
            confirm-button-text="是"
            cancel-button-text="否"
            @confirm="confirmEvent(scope.$index, scope.row)"
          >
            <template #reference>
              <el-button size="small">删除</el-button>
            </template>
          </el-popconfirm>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      v-model:current-page="pageNo"
      v-model:page-size="pageSize"
      @current-change="handleCurrentChange"
      small
      background
      layout="total, prev, pager, next"
      :total="total"
      class="pagination fxr"
    />
  </div>
</template>

<script>
import pubJs from "./pub";
import axios from "axios";

export default {
  mixins: [pubJs],
  data() {
    return {
      pingsztlb: [],
      formData: {
        pingszt: "1",
      },
      soustjList: [],
      userInfo: JSON.parse(localStorage.getItem("userInfo")),
      tableHeader: [],
    };
  },
  async mounted() {
    this.saisId = localStorage.getItem("saisId");
    await this.getDongtsstjlb(this.saisId)
    this.getTableHeader()
    this.getDictItem()
    console.log(this.soustjList,'this.soustjList');
    if (this.searchFormData && Object.keys(this.searchFormData).length != 0) {
      this.formData.pingszt = this.searchFormData.pingszt
        ? this.searchFormData.pingszt
        : "";
      this.pageNo = this.searchFormData.pageNo;
    }
    // this.getData();
    setTimeout(()=>{
      this.getData(this.pageNo);
    },200)
  },

  methods: {
    confirmEvent(idx, row) {
      let that = this;

      axios
        .delete(that.serviceUrl + "/saisjczd2/cbda2Saisjczd/deletePingsjl", {
          headers: {
            "X-Access-Token": localStorage.getItem("token"),
          },

          params: {
            saisId: that.saisId,
            pingsId: row.id,
          },
        })
        .then((resp) => {
          if(resp&&resp.data.code==200){
            this.getData(1);
            this.$message.success("删除成功");
          }else{
            this.$message.success(resp.data.message);
          }
        })
        .catch((error) => {
          //console.log(error);
          this.$message.error(error);
        });
    },

    //评审状态
    getDictItem() {
      let that = this;
      axios
        .get(that.serviceUrl + "/sys/dictItem/list", {
          headers: {
            "X-Access-Token": localStorage.getItem("token"),
          },
          params: {
            dictId: "1782630545334263809",
            _t: new Date().getTime(),
          },
        })
        .then((resp) => {
          that.pingsztlb = resp.data.result.records;
        })
        .catch((error) => {
          //console.log(error);
        });
    },
    // 获取表头
    getTableHeader() {
      let that = this;
      axios
        .get(that.serviceUrl + "/saisjczd2/cbda2Saisjczd/getWodspzd", {
          headers: {
            "X-Access-Token": localStorage.getItem("token"),
          },
          params: {
            cansrsf: that.userInfo.cansrsf,
            saisId: that.saisId,
            _t: new Date().getTime(),
          },
        })
        .then((resp) => {
          resp.data.result.forEach((item, index) => {
            that.tableHeader.push({
              ...item,
              width:
                item.zidmc == "create_time"
                  ? 200
                  : item.zidmc == "pingszt"
                  ? 240
                  : item.zidmc == "pingf"
                  ? 100
                  : "",
            });
          });
        })
        .catch((error) => {
          //console.log(error);
        });
    },
    returnGo() {
      this.$router.go(-1); // 返回上一个页面
    },

    reset() {
      this.formData = {
        saisId: this.saisId,
        pingszt: "1",
      };
      this.pageNo = 1
      this.getData();
    },

    getData(v) {
      let that = this;
      this.tableLoading = true;
      axios
        .post(
          that.serviceUrl + "/saisjczd2/cbda2Saisjczd/pingslieb",
          {
            ...that.formData,
            saisId: this.saisId,
            pageNo: this.pageNo,
            pageSize: this.pageSize,
          },
          {
            headers: {
              "X-Access-Token": localStorage.getItem("token"),
            },
          }
        )
        .then((resp) => {
          console.log(resp, "getData");
          if (resp && resp.data.code == 200) {
            this.tableLoading = false;
            that.tableData = resp.data.result.records;
            that.total = resp.data.result.total;
          }
        })
        .catch((error) => {
          //console.log(error);
        });
    },

    // 撤回
    withdraw(index, row) {
      this.$router.push({ path: "project", query: row });
    },

    oper(index, row) {
      localStorage.setItem("topStepId", row.saisjc_id);
      localStorage.setItem(
        "searchFormData",
        JSON.stringify({ ...this.formData, pageNo: this.pageNo })
      );
      this.$router.push({
        path: "pings",
        query: {
          id: row.id,
          saisId: row.sais_id,
          canszpId: row.canszp_id,
          saisjcId: row.saisjc_id,
          saisqyId: row.saisqy_id,
        },
      });
    },
  },
};
</script>

<style scoped lang="less"></style>
